package com.cumt.threeway.activity;

import java.util.ArrayList;
import java.util.List;

import com.cumt.threeway.R;
import com.cumt.threeway.adapter.LoadingAdapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class NavigationActivity extends Activity implements OnClickListener,OnPageChangeListener{
	
	private List<View> mList;
	private LinearLayout mLinearLayout;
	private int mCurrentDot;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_navigation);
		initView();
	}

	private void initView() {
		mList = new ArrayList<View>();
		mLinearLayout = (LinearLayout) findViewById(R.id.ll_dotView);
		ViewPager vp = (ViewPager) findViewById(R.id.vp);
		mCurrentDot = 0;
		vp.setOnPageChangeListener(this);
		View view1 = LayoutInflater.from(this).inflate(R.layout.activity_help1, null);
		mList.add(view1);
		View view2 = LayoutInflater.from(this).inflate(R.layout.activity_help2, null);
		mList.add(view2);
		View view3 = LayoutInflater.from(this).inflate(R.layout.activity_help3, null);
		view3.findViewById(R.id.btn_begin).setOnClickListener(this);
		mList.add(view3);
		LoadingAdapter loadingAdapter = new LoadingAdapter(mList);
		vp.setAdapter(loadingAdapter);
	}

	@Override
	public void onClick(View v) {
		goMainManageActivity();
	}

	private void goMainManageActivity() {
		startActivity(new Intent(this, MainManageActivity.class));
		finish();
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
		
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		
	}

	@Override
	public void onPageSelected(int position) {
		setDotChange(position);
	}

	public void setDotChange(int position) {
		if (mLinearLayout.getChildAt(position) instanceof ImageView) {
			((ImageView)mLinearLayout.getChildAt(position)).setBackgroundResource(R.drawable.pagination_dot_selected);
			((ImageView)mLinearLayout.getChildAt(mCurrentDot)).setBackgroundResource(R.drawable.pagination_dot);
		}
		mCurrentDot = position;
	}
}
